<template>
  <div style="height:100%;width:100%">
    <el-row class="mainContent" >
      <!--工具条-->
      <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
        <el-form :inline="true" :model="filters" size="small" style="text-align:left;" :rules="filte" ref="filters">
          <el-form-item prop="id">
            <el-input v-model="filters.keyword" placeholder="用户名/手机号" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-select v-model="filters.state" placeholder="状态" clearable>
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <div class="block">
              <el-date-picker
                v-model="filters.begtime"
                type="datetime"
                placeholder="选择日期">
              </el-date-picker>
              <el-date-picker
                v-model="filters.endtime"
                type="datetime"
                placeholder="选择日期">
              </el-date-picker>
            </div>
          </el-form-item>
          <el-form-item>
            <el-button type="primary"  @click="getUsers">查询</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <!--列表-->
      <el-table :data="users" highlight-current-row  v-loading="listLoading" style="width: 100%;">

        <el-table-column  label="方案ID" prop="cingid" >
        </el-table-column>
        <el-table-column  label="手机号" prop="mobile" >
        </el-table-column>
        <el-table-column prop="nickname" label="用户名" >
        </el-table-column>

        <!--<el-table-column  label="扣息基数"  prop="baseAmount">-->
        <!--</el-table-column>-->
        <el-table-column  label="扣息金额" prop="dayfee" >
        </el-table-column>
        <el-table-column  label="状态"  >
          <template slot-scope="scope">
            {{scope.row.state | stateFormat}}
          </template>
        </el-table-column>
        <el-table-column prop="feeTime" label="扣费时间" >
        </el-table-column>
        <el-table-column  label="操作" v-if="$store.state.routes.routes.ywBqOperate">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="editMoney(scope.$index, scope.row)" :disabled="scope.row.state==15">补扣</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10"  :total="total" style="float:right;">
      </el-pagination>
    </el-row>

    <el-dialog title="补扣" :visible.sync="dialogFormVisible" width="30%" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form :model="editForm" ref="editPwdForm" status-icon label-width="100px" :rules="editFormRules" style="text-align:left">
        <el-form-item label="ID" prop="cingid">
          <el-col :span="22">
            <el-input disabled v-model="editForm.cingid" placeholder=""></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="用户名" prop="nickname">
          <el-col :span="22">
            <el-input disabled v-model="editForm.nickname" placeholder=""></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="手机号" prop="mobile">
          <el-col :span="22">
            <el-input disabled  v-model="editForm.mobile" placeholder=""></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="可用余额" prop="amountAvailable">
          <el-col :span="22">
            <el-input disabled  v-model="editForm.amountAvailable" placeholder=""></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="补扣金额" prop="dayfee">
          <el-col :span="22">
            <el-input  v-model="editForm.dayfee" placeholder="" disabled></el-input>
          </el-col>
        </el-form-item>
        <!--<el-form-item label="扣费基数" prop="baseAmount">-->
        <!--<el-col :span="22">-->
        <!--<el-input v-model="editForm.baseAmount" placeholder="" disabled></el-input>-->
        <!--</el-col>-->
        <!--</el-form-item>-->
        <el-form-item label="对应日期" prop="reNewPwd">
          <el-col :span="22">
            <el-input  v-model="editForm.time" placeholder="" disabled></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click.native="submitDialog" :loading="editPwdLoading">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        options: [{
          value: '15',
          label: '扣息成功 '
        }, {
          value: '20',
          label: '扣息失败'
        }],
        filters: {
          begtime:'',
          endtime:"",
          keyword: "",
          state:'',
        },
        editForm:{},
        editFormRules:{},
        users:[],
        page: 1,
        total: 0,
        listLoading: false,
        filte:{},
        dialogFormVisible:false,
        editPwdLoading:false
      };
    },
    filters:{
      stateFormat(val){
        switch (val){
          case 15:
            return '扣息成功';
            break
          case 20:
            return '扣息失败';
            break
        }
      }
    },
    created() {
      if(this.$route.query.state){
        this.filters.state = this.$route.query.state.toString()
      }
      this.getUsers();
    },
    methods: {
      getUsers() {
        this.users = []
        this.listLoading = true;
        var obj = {
          data:{
            keyword: this.filters.keyword,
            state:this.filters.state,
            begtime:this.filters.begtime==''||this.filters.begtime==0||this.filters.begtime==null?"":Date.parse(this.filters.begtime).toString().substr(0,10),
            endtime:this.filters.endtime==''||this.filters.endtime==0||this.filters.endtime==null?"":Date.parse(this.filters.endtime).toString().substr(0,10),
            pageNo:this.page
          }
        };
        this.$http('sys/financingdayfee/list.do',obj).then(resp => {
          if(resp.code==1){
            this.users = resp.data.list;
            this.total = resp.data.total;
          }
          this.listLoading = false;
        });

      },
      handleCurrentChange(val) {
        this.page = val;
        this.getUsers();
      },
      editMoney(index,row){
        if(!this.$store.state.routes.routes.ywBqOperate){
          this.$message({
            message:'无权限',
            type:'error'
          })
          return
        }
        this.editForm = row
        this.editForm.time = this.getDate()
        this.dialogFormVisible = true;
      },
      submitDialog(){

        this.editPwdLoading = true
        var obj = {
          data:{
            id:this.editForm.id
          }
        };
        this.$http('sys/financingdayfee/deduct.do',obj).then(resp=> {
          if(resp.code!=1){
            this.$message({
              message:resp.msg,
              type:'error'
            })
          }else{
            this.$message({
              message:'补扣成功',
              type:'success'
            })
          }
          this.getUsers()
          this.editPwdLoading = false
        })
        this.dialogFormVisible = false;
        this.editForm = {}

      },
      getDate(){
        var date = new Date();
        var nowMonth = date.getMonth() + 1;
        var strDate = date.getDate();
        var seperator = "-";
        if (nowMonth >= 1 && nowMonth <= 9) {
          nowMonth = "0" + nowMonth;
        }
        if (strDate >= 0 && strDate <= 9) {
          strDate = "0" + strDate;
        }
        return  date.getFullYear() + seperator + nowMonth + seperator + strDate;
      }
    }
  }
</script>

<style scoped>


  .el-table:hover{
    cursor: pointer !important;
  }
</style>
